// 获取所有api_开头的文件
let fs = require("fs");
let path = require("path");

// 获取的当前项目的根目录
let rootPath = path.resolve(__dirname, "..");
// 获取每一个文件夹下的文件
let getFiles = (dir) => {
    let files = fs.readdirSync(dir);
    let result = [];
    for (let i = 0; i < files.length; i++) {
        let file = files[i];
        let filePath = path.resolve(dir, file);
        let stat = fs.statSync(filePath);
        if (stat.isDirectory()) {
            result = result.concat(getFiles(filePath));
        } else {
            result.push(filePath);
        }
    }
    return result;
}

// 获取所有文件
let allFiles = getFiles(rootPath);
// 获取所有api_开头的文件
let apiFiles = allFiles.filter((file) => {
    let filename = path.basename(file);
    return filename.startsWith("api_")&&filename.endsWith(".js");
});
// 转换成对应项目的路径
apiFiles = apiFiles.map((file) => {
    return path.relative(rootPath, file);
});


console.log(apiFiles);